package org.NS.qmuisc;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;


public class PlayListAdapter extends SimpleAdapter {

    private static int[] mColors = { R.drawable.grey, R.drawable.white };
    
    private int mSelectedItem = -1;
    private int mNextItem = -1;
    
    public PlayListAdapter(Context context,
            List<? extends Map<String, ?>> data, int resource, String[] from,
            int[] to) {
        super(context, data, resource, from, to);
        // TODO Auto-generated constructor stub
    }
    
    public void setSelectedItem(int selectPosition){
    	mSelectedItem = selectPosition;
    	if(mSelectedItem == mNextItem)
    		mNextItem = -1;
    }
    
    public int getCurrentItem(){
    	return mSelectedItem;
    }
    
    public void setNextItem(int nextPosition){
    	if(nextPosition == mSelectedItem){
    		return;
    	}
    	mNextItem = nextPosition;    
    }
    
    public int getNextItem(){
    	return mNextItem;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        int[] arrayOfInt = mColors;
        int colorLength = mColors.length;
        int listColor = arrayOfInt[position % colorLength];
        View localView = super.getView(position, convertView, parent);
        if(position == mSelectedItem){
        	localView.setBackgroundResource(R.drawable.selected);        	
        }
        else if(position == mNextItem){
        	localView.setBackgroundResource(R.drawable.next_color);
        }
        else{
        	localView.setBackgroundResource(listColor);
        }        
        return localView;
    }
}
